package org.hong.monkey.broadcast

import org.hong.monkey.MonkeyConf

import scala.reflect.ClassTag

/**
 * A [[org.hong.monkey.broadcast.BroadcastFactory]] implementation that uses a
 * HTTP server as the broadcast mechanism. Refer to
 * [[org.hong.monkey.broadcast.HttpBroadcast]] for more details about this mechanism.
 */
class HttpBroadcastFactory extends BroadcastFactory {
  override def initialize(isDriver: Boolean, conf: MonkeyConf) {
    HttpBroadcast.initialize(isDriver, conf)
  }

  override def newBroadcast[T: ClassTag](value_ : T, isLocal: Boolean, id: Long): Broadcast[T] =
    new HttpBroadcast[T](value_, isLocal, id)

  override def stop() { HttpBroadcast.stop() }

  /**
   * Remove all persisted state associated with the HTTP broadcast with the given ID.
   * @param removeFromDriver Whether to remove state from the driver
   * @param blocking Whether to block until unbroadcasted
   */
  override def unbroadcast(id: Long, removeFromDriver: Boolean, blocking: Boolean) {
    HttpBroadcast.unpersist(id, removeFromDriver, blocking)
  }
}
